# ifndef __RGNodes_H_
# define __RGNodes_H_

# include "String.h"

struct rgn_t;
struct map_t;

//
// The routing graph nodes.
//

struct rgnode_t {
	DWORD dwNodeID;
	bool bIsExternal;
	bool bIsTrimNode;
	bool bHasRestrictions;

	// The number of routable inputs and outputs.
	BYTE btCardinality;
	// The number of polylines crossing the node. NOTE: self-intersection increases this counter by 2.
	BYTE btPolylines;
	// Internal tmp counter used in drawing.
	mutable BYTE btDrawCount;

	// Used for tmp purposes.
	mutable void * pExtra;

	rgnode_t () :
		btCardinality (0),
		btPolylines (0),
		btDrawCount (0),
		dwNodeID (-1),
		pExtra (NULL),
		bIsExternal (false),
		bIsTrimNode (false),
		bHasRestrictions (false)
	{}

	bool IsUsed () const {return btPolylines != 0;}
};

typedef std::list<rgnode_t> rgnodes_t;

//
// Turn restrictions.
//

struct rgrestriction_t {
	rgnode_t * pNode;
	rgn_t * pFromRoad, * pToRoad;
	DWORD bFromDirection, bToDirection; // true if forward direction
	string_t strTime;

	bool IsUsed () const;
	bool IsValid () const;
};

typedef std::multimap<rgnode_t *, rgrestriction_t> rgrestrictions_t;
rgrestriction_t & AddRGNodeRestriction (map_t & _map, rgnode_t * _pNode);
rgrestrictions_t::iterator FindRGNodeRestriction (rgrestrictions_t & _rgrestrictions, const rgrestriction_t & _restriction);

const rgnode_t * GetRGNode (const rgn_t & _rgn, size_t _cElement, size_t _cPoint);
      rgnode_t * GetRGNode (      rgn_t & _rgn, size_t _cElement, size_t _cPoint);

# endif // __RGNodes_H_